//
//  MBaseTableVC.swift
//  iOSweibo
//
//  Created by lzm on 16/5/11.
//  Copyright © 2016年 lzm. All rights reserved.
//

import UIKit

class MBaseTableVC: UITableViewController {

    var userLogin = MUserAccountViewModel.sharedInstance.isUserLogin
    override func loadView() {
        if userLogin {
            super.loadView()
        }
        else
        {
            view = visitorView
//            view.backgroundColor = UIColor.brownColor()
            //5.设置代理
            visitorView.delegate = self
            if self is MHomeViewController
            {
            
                visitorView.starRotationAnimation()
            }
            else if self is MMessageViewController
            {
                visitorView.setVisitorView("visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
            }
            else if self is MDicoveryViewController
            {
                visitorView.setVisitorView("visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
            }
            else if self is MMeViewController
            {
                visitorView.setVisitorView("visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
            }
            //设置导航栏按钮
            self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewDidClickRegister")
            self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewDidClickLogin")
            
        }
    }
    //懒加载 - 访客
    private lazy var visitorView :MVisitorView = MVisitorView()
}
//MARK: -- 代理方法扩展
//6.遵守代理
extension MBaseTableVC :MVisitorViewDelegate
{
    //7.实现代理方法
    func visitorViewDidClickRegister() {
        print(__FUNCTION__)
    }
    func visitorViewDidClickLogin() {
        let oauth = MOauthViewController()
        
        self.presentViewController(UINavigationController(rootViewController: oauth), animated: true, completion: nil)
    }
}
